package org.zk.service.impl;

import org.zk.dao.PurseMapper;
import org.zk.entity.Purse;
import org.zk.service.PurseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PurseServiceImpl implements PurseService {

    @Autowired
    private PurseMapper purseMapper;

    @Override
    public Purse getByUid(Integer uid) {

        return purseMapper.selectPurseByUid(uid);
    }

    @Override
    public Integer addPurse(Purse purse) {

        return purseMapper.insertPurse(purse);
    }

    @Override
    public Integer rechargePurse(Integer uid, Float money) {


        if(purseMapper.selectPurseByUid(uid) != null){

            Integer rst = purseMapper.updatePurse(uid, Float.valueOf(money));
            if (rst > 0) {
                return 1;
            }
        }

        return 0;
    }




}
